#include "leftendmf.h"

LeftEndMF::LeftEndMF() : GraphicalMF("Left End", 3)
{
    /* Set the x and y values */
    m_points[0].setX(0);
    m_points[0].setY(1);

    m_points[1].setX(1);
    m_points[1].setY(1);

    m_points[2].setX(2);
    m_points[2].setY(0);
}

LeftEndMF::LeftEndMF(double newPoints[]) : GraphicalMF("Left End", 3)
{
    /* Set the x and y values in accordance to the array that was passed in */
    m_points[0].setX(newPoints[0]);
    m_points[0].setY(1);

    m_points[1].setX(newPoints[1]);
    m_points[1].setY(1);

    m_points[2].setX(newPoints[2]);
    m_points[2].setY(0);
}

LeftEndMF::~LeftEndMF()
{
}

void LeftEndMF::paint(QPainter *painter, const double &xShift,
                      const double &xScale, const double &yShift,
                      const double &yScale) const
{
    /* Paint in the generic GraphicalMF style */
    this->GraphicalMF::paint(painter, xShift, xScale, yShift, yScale);

    /* Draw the name of the MF above it and near the center */
    painter->drawText(xShift + xScale * (m_points[2].x() + m_points[0].x())/2,
                      yShift + yScale - 4,
                      this->getName());
}

void LeftEndMF::calculateCentroid()
{
    m_crisp_value=m_points[1].x();
}

void LeftEndMF::calculateProbability(const double& crispInput)
{
    if (crispInput<= m_points[1].x())
    {
        m_fuzzy_value=1;
    }
    else if (crispInput>= m_points[2].x())
    {
        m_fuzzy_value=0;
    }
    else if ( m_points[1].x() < crispInput && crispInput <= m_points[2].x())
    {
        m_fuzzy_value=(m_points[2].x()-crispInput)/
                      (m_points[2].x()-m_points[1].x());
    }

}
